// 非空验证
$('#name input').blur(() => {
  $('#name p').text('');
  if ($('#name input').val() == '') {
    $('#name p').text('用户名不能为空！');
  }
})
$('#password input').blur(() => {
  $('#password p').text('');
  if ($('#password input').val() == '') {
    $('#password p').text('密码不能为空！');
  }
})

// 登录验证
$('#btn input').click(function () {
  let name = $('#name input').val();
  let password = $('#password input').val();

  $('#name p').text('');
  $('#password p').text('');
  if (name == '') {
    $('#name p').text('用户名不能为空！');
    return
  }
  if (password == '') {
    $('#password p').text('密码不能为空！');
    return
  }
  console.log(1)
  $.ajax({
    url:'http://localhost:8089/api/login',
    type:'post',
    data:{
      username:name,
      password:password
    },
    success:function(data){
      console.log(2)
      if(data.resultCode == 1){
        alert('登录成功！');
        localStorage.setItem('userDaea', JSON.stringify(name))
        location.href='./pages/index.html';
      }else{
        $('#name p').text('密码或用户名出错！');
      }
    }
  })
  console.log(3)
})
